var app = getApp()
Page({
        data: {
                msg:[],
                imgPath:""
        },
        onLoad: function (options) {
                var that = this
                var data = app.globalData.data
                that.setData({
                        msg: data,
                });
                wx.setNavigationBarTitle({
                        title: '修改信息'
                        })
        },
        selectImg: function () {
                var that = this;
                wx.chooseImage({
                  count: 1,
                  sizeType: ['original', 'compressed'],
                  sourceType: ['album', 'camera'],
                  success: function (res) {
                    //res.tempFilePaths 返回图片本地文件路径列表
                    var tempFilePaths = res.tempFilePaths;
                    that.setData({
                      imgPath: tempFilePaths[0]
                    })
            
                  }
                })
              },
              previewImg: function (e) {
                var img = this.data.imgPath;
                // 设置预览图片路径
                wx.previewImage({
                  current: img,
                  urls: [img]
                })
              },
              nihao(e){
                      var name = e.detail.value.name
                      var img = this.data.imgPath
                      var find_id = this.data.msg[0].id
                //       console.log(name)
                //       console.log(img)
                //       console.log(this.data.msg[0].id)
                wx.request({
                        url: 'http://localhost:3000/add_img',
                        method:"POST",
                        data:{
                                find_id:find_id,
                                name:name,
                                img:img
                        },
                        success: (res) => {
                                if(res.data == "修改成功"){
                                        wx.showToast({
                                                title: '修改成功，重新登录就可以看到',
                                                icon: 'none',
                                                duration: 1000,
                                        })
                                }
                        }
                      })
              }
})